﻿using B.S.Filtration.ErrorCode;
using B.S.Filtration.Write.Api.Application.Command.VendorItems;
using B.S.Filtration.Write.Api.Application.Command.VendorItemsCommand;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Filtration.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class VendorItemsController : ControllerBase
    {

        private readonly IMediator mediator;

        public VendorItemsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加供应商物品
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddVendorItems(AddVendorItemsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除供应商物品
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DelVendorItems(DelVendorItemsCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 修改供应商物品
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdVendorItems(UpdVendorItemsCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
